package com.dhecp.project.storage.controller;

import com.dhecp.common.annotation.RepeatSubmit;
import com.dhecp.common.core.domain.AjaxResult;
import com.dhecp.common.core.page.TableDataInfo;
import com.dhecp.common.enums.BusinessType;
import com.dhecp.core.constant.ModuleTable;
import com.dhecp.core.utils.ExportExcelUtils;
import com.dhecp.project.storage.domain.HwStorage;
import com.dhecp.project.storage.service.HwStorageService;
import com.dhecp.project.system.domain.SysDictionaryForExport;
import com.dhecp.project.system.service.SysDictionaryForFieldService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import com.dhecp.project.common.controller.BaseModuleController;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import com.dhecp.common.annotation.Log;
import org.springframework.web.servlet.ModelAndView;

/**
 * 海外仓库存管理(HwStorage)控制层
 *
 * @author fxz
 * @since 2024-02-28 13:45:26
 */
@Controller
@RequestMapping("/storage/hwStorage")
public class HwStorageController extends BaseModuleController{
    private String prefix = "/storage/hwStorage";
    private String moduleTable = ModuleTable.HW_STORAGE;
    
    @Autowired
    private HwStorageService hwStorageService;

    @Autowired
    private SysDictionaryForFieldService dictionaryForFieldService;
    
    /**
     *@Description: 打开查询列表页
     *@Param: [params]
     *@return: org.springframework.web.servlet.ModelAndView
     *@Author: fxz
     *@date: 2024-02-28 13:45:26
     */
    @RequiresPermissions("storage:hwStorage:view")
    @GetMapping()
    public ModelAndView listPage(@RequestParam Map<String, Object> params){
        params.put("moduleTable", moduleTable);
        params.put("entity", new HwStorage()); //生成表格gridColumns对应的实体，用于获取实体属性生成表格字段
        params.put("prefix", prefix + "/hwStorage"); //页面路径
        params.put("toolBarWidth", 0);
        params.put("checkBox", "yes");

        ModelAndView mv = this.openListPage(params);
        mv.addObject("storage", "hwStorage");
        mv.setViewName(prefix + "/hwStorage");
        return mv;
    }
    
     /**
     *@Description: 查询页 列表数据
     *@Param: [params]
     *@return: com.dhecp.common.core.page.TableDataInfo
     *@Author: fxz
     *@date: 2024-02-28 13:45:26
     */
    @RequiresPermissions("storage:hwStorage:list")
    @GetMapping("/list")
    @ResponseBody
    public TableDataInfo list(@RequestParam Map<String, Object> params){
        params.put("moduleTable", moduleTable);
        List<HwStorage> list = new ArrayList<HwStorage>();
        try {
            list = hwStorageService.queryList(params);
        } catch (Exception e) {
            e.printStackTrace();
            return getDataTable(this.getExceptionMessage(e).toString());
        }
        return getDataTable(list);
    }
    
     /**
     *@Description: 数据导出Excel
     *@Param: [params]
     *@return: com.dhecp.common.core.domain.AjaxResult
     *@Author: fxz
     *@date: 2024-02-28 13:45:26
     */
    @RequiresPermissions("storage:hwStorage:export")
    @Log(title = "导出", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    @ResponseBody
    @RepeatSubmit
    public AjaxResult export(@RequestParam Map<String, Object> params) throws Exception {
        params.put("moduleTable", moduleTable);
        params.put("entity", new HwStorage());

        List<HwStorage> list = hwStorageService.queryList(params);

        params.put("getFieldAttributesType", "export");
        List<SysDictionaryForExport> fieldList = dictionaryForFieldService.queryExportFieldList(params);
        ExportExcelUtils<HwStorage> util = new ExportExcelUtils<HwStorage>(moduleTable,new HwStorage());
        return util.exportExcel(list, fieldList, "海外仓库存管理", "export");
    }
}

